<template>
  <div class="box">
    <div>
      <van-search
        v-model="value"
        show-action
        shape="round"
        background="#4fc08d"
        placeholder="请输入搜索关键词"
        @search="onSearch"
        @focus="gosearch"
      >
        <template #left>
          <div class="dizhi" @click="onClickButton2">地址</div>
        </template>
        <template #action>
          <!--根据登录状态 条件渲染 -->
          <div @click="onClickButton" v-if="!token">登录</div>
          <div @click="onClickButton1" v-if="token">我的</div>
        </template>
      </van-search>
    </div>
    <div class="swiper">
      <swiper></swiper>
    </div>
    <div class="jindong">
      <jingd></jingd>
    </div>
    <div>
      <div class="CountDownTime">
        <span>京东秒杀</span>
        <!-- 秒杀计时器 -->
        <span style="color: red">{{ times }}点专场</span>
        <van-count-down :time="time">
          <template #default="timeData">
            <span class="block">{{ timeData.hours }}</span>
            <span class="colon">:</span>
            <span class="block">{{ timeData.minutes }}</span>
            <span class="colon">:</span>
            <span class="block">{{ timeData.seconds }}</span>
          </template>
        </van-count-down>
      </div>
      <seckilllist></seckilllist>
    </div>
    <div>
      <list></list>
    </div>
  </div>
</template>

<script setup lang="ts">
import swiper from "./home/swiper.vue";
import jingd from "./home/jingd.vue";
import seckilllist from "./home/seckilllist.vue";
import list from "./home/list.vue";
import {type Ref, ref, reactive ,onMounted} from "vue";
import { useRouter } from "vue-router";
import {useCounterStore} from "../stores/counter";


let counterStore = useCounterStore();
let router = useRouter();
let times = ref<any>("");
let value = ref("");
let token = ref<any>("");
let time = ref(1 * 60 * 60 * 1000);

function onSearch() {}
function onClickButton() {
  router.push("/login");
}
function onClickButton1() {
  router.push("/mine");
}
function onClickButton2() {
  router.push("/mine");
}
function gosearch() {
  router.push("/search");
}
function getTimes() {
  setInterval(getTimesInterval, 3600000 * 1000);
}
function getTimesInterval() {
  let hours = ref<any>(new Date().getHours());
  //获取当前时间的小时
  //当小于 10 的是时候，在前面加 0
  if (hours < 10) {
    hours = "0" + hours;
  }
  times.value = hours;
}
onMounted(()=>{
    // console.log(this.$store.state.userInfo);
    token.value = localStorage.getItem("token");
    // this.$store.commit("channav", true);
    counterStore.channav(true)
    getTimes();
})
</script>

<style lang="scss" scoped>
.swiper {
  width: 100%;
  height: 200px;
}
.jindong {
  width: 100%;
}
.dizhi {
  font-size: 16px;
}
.CountDownTime {
      display: flex;
      justify-content: space-between;
      padding: 20px 20px;
      font-size: 16px;
      
      .colon {
        display: inline-block;
        font-size: 20px;
        padding: 0 10px;
        color: red;
      }
      .block {
        display: inline-block;
        width: 26px;
        height: 26px;
        line-height: 26px;
        color: #fff;
        font-size: 20px;
        text-align: center;
        background-color: red;
      }
    }
.box{
  width: 100%;
  overflow: hidden;
}
</style>

